<?php

	header( 'Content-Type: application/javascript' );
	
	function packJs( $p_srcDir )
	{
		$data = "";
		$jsFiles = scanRecursively( $p_srcDir ); 
		$bigJs = "";
		
		foreach( $jsFiles as $jsFile )
		{
			$data  = file_get_contents( $jsFile );
			$bigJs .= "\n\n//***********************************************************************";
			$bigJs .= "\n\n//**************************".$jsFile."**************************";
			$bigJs .= "\n\n//***********************************************************************";
			$bigJs .= "\n\n".$data."\n\n";
		}
		
		return $bigJs;
	}

	function scanRecursively( $p_dir )
	{
			
		$list = scandir( $p_dir );
		$fileList = array();
		$isFile = false;
		
		foreach( $list as $file )
		{
			
			if ( $file == ".." || $file == '.' )
				continue;
				
			$isFile = is_file( $p_dir.$file );
			
			if ( $isFile )
			{
				$fileList[] = $p_dir.$file;
			}
			else
			{
				$fileList = array_merge( $fileList, scanRecursively( $p_dir.$file."/" ) );
			}
			
		}
		
		return $fileList;
	}
	
	$jsDir = realpath( getcwd() ).'/src/js/game/';
	
	if ( file_exists($jsDir."maker.js"))
	{
		unlink($jsDir."maker.js");
	}
	
	
	
	$data = packJs( $jsDir );
	

		
	file_put_contents($jsDir."../maker.js", $data);
	
	
?>